#ifndef prs_FrmString_H
#define prs_FrmString_H

#include "prs_Rule.h"
#include "prs_FrmControl.h"
#include "prs_FrmUseTemplate.h"
#include "prs_FrmStringStyle.h"
#include "frm_control_TStringEdit.h"

namespace prs {
            
///////////////////////////////////////////////////////////////////////////////
struct TNodeFrmString;
///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmStringControl : public frm::control::TStringEdit
{
  TNodeFrmStringControl(
    frm::control::TWindow &Window,
    TNodeFrmString &Node
  ):TStringEdit(Window),node(Node) {}
  //
  virtual bool UpdateValue(svl::TString V);
  
private:  
  TNodeFrmString &node;
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmString : public TNodeFrmControl
{
  DECLARE_ClientNode()
  //
  typedef TNodeFrmStringStyle   TStyle;
  typedef TNodeFrmStringControl TControl;
  //
  TAttrNodeType<nodeType_String> NodeType;
  TAttrBindPropString<attrName_Value,TNodeUseTemplateParam*> Value;
  TAttrBool<attrName_EnEdit> EnEdit;
  TAttrPointerNoCopy<attrName_Control,TNodeFrmStringControl*> Control;
  //
  TNodeFrmString()
    :NodeType(this)
    ,Value(this)
    ,Control(this)
    ,EnEdit(this)
    ,controlEvents(this) 
  { 
    EnEdit = true; 
  }
 ~TNodeFrmString() { delete Control.GetValue(); }
  //
  TNodeFrmStringControl *BuildControl(
    frm::control::TPanel *ParentControl
  );
  
private:
  virtual void TNode_SetPropPointerValue(TAttrPointerBase &Attr,svl::TPointer *V);
  //
  virtual void          TNode_SetPropStringValue(TAttrStringBase &Attr,svl::TString &V);
  virtual void          TNode_AddPropStringValue(TAttrStringBase &Attr,svl::TString &V);
  virtual svl::TString &TNode_GetPropStringValue(TAttrStringBase &Attr);
  //
  void updateValueInControl();
  //
  svl::TString value;
  TNodeFrmControlEvents controlEvents;  
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////

struct TRuleFrmString : public snt::TRule ,public TFrmDict
{
  TRuleFrmString(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode,
    TRuleFrmChildrenBase &RFrmChildren,
    TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
    TRuleSetAttrValue &RSetAttrValue,
    TRuleSetStyle &RStyle
  );

private:  
  bool FSetParamString(TRuleSetAttrValue::TFuncValueIdentParams &Params) {
    return TNodeDefTemplate::AddLinkAttrByParamId(Params.Attr,TFrmStringValue(),Params.Ident,Params.OutError);
  }
  bool FSetParamBool(TRuleSetAttrValue::TFuncValueIdentParams &Params) {
    return TNodeDefTemplate::AddLinkAttrByParamId(Params.Attr,TFrmBoolValue(),Params.Ident,Params.OutError);
  }
  //
  svl::TVariant &vParentNode;
  snt::TAlter AAttr1;
  snt::TRule  RAttr1,RAttr;

  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
